<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/5/1
 * Time: 22:03
 */

namespace Lib\Api;


class OrderCommissionApi extends UtilsApi {
    private static $modelName = 'OrderCommission';

    /** 获取订单返佣列表
     * @param $where
     * @param $join
     * @param $page_num
     * @param $page_size
     * @param string $field
     * @param string $group
     * @param string $order
     * @return mixed
     */
    public static function getListByCondition($where, $join="", $page_num = 1, $page_size = 15, $field = "*", $group = "", $order = "") {
        $model = M();
        $list = $model->table('fs_order_commission a')
            ->join($join)
            ->field($field)
            ->where($where)
            ->order($order)
            ->group($group)
            ->page($page_num, $page_size)
            ->select();
        return $list;
    }

    /** 获取订单返佣总数
     * @param $where
     * @param $join
     * @return mixed
     */
    public static function getTotalByCondition($where, $join="") {
        $model = M();
        $total = $model->table('fs_order_commission a')
            ->join($join)
            ->where($where)
            ->count("a.id");
        return $total;
    }

    /** 获取订单返佣列表
     * @param $where
     * @param int $page_num
     * @param int $page_size
     * @param string $field
     * @return mixed
     */
    public static function getList($where, $page_num = 1, $page_size = 15, $field = "*") {
        $list = parent::getList(OrderCommissionApi::$modelName, $where, $page_num, $page_size, $field);
        return $list;
    }

    /** 获取订单返佣总数
     * @param $where
     * @return mixed
     */
    public static function getTotal($where) {
        $total = parent::getTotal(OrderCommissionApi::$modelName, $where);
        return $total;
    }

    /** 获取订单返佣信息
     * @param $where
     * @param $field
     * @return mixed
     */
    public static function getInfo($where, $field= "*") {
        $manager = parent::getInfo(OrderCommissionApi::$modelName, $where, $field);
        return $manager;
    }

    /** 添加订单返佣
     * @param $data
     * @return mixed
     */
    public static function add($data) {
        $id = parent::add(OrderCommissionApi::$modelName, $data);
        return $id;
    }

    /** 修改订单返佣
     * @param $data
     * @return bool
     */
    public static function save($data) {
       $state = parent::save(OrderCommissionApi::$modelName, $data);
        return $state;
    }

    /** 保存数据
     * @param $where
     * @param $data
     * @return bool
     */
    public static function saveByCondition($where, $data) {
        $model = M(OrderCommissionApi::$modelName);
        return $model->save($data)->where($where) ;
    }

    /** 删除订单返佣
     * @param $where
     */
    public static function delete($where) {
        parent::delete(OrderCommissionApi::$modelName, $where);
    }

    /** 批量添加数据
     * @param $data
     * @return mixed
     */
    public static function addAll($data) {
        $model = M(OrderCommissionApi::$modelName);
        return $model->addAll($data);
    }
}